package com.atguigu.mq.listener;


import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @Author 快点干早点散
 * @Create 2025/4/20 20:16
 * Description:
 * <p>
 * 消费者
 */

@Component
public class MyMessageListener {
    //默认采用自动处理确认消息,消费者获取消息处理后,自动给服务器发送异步确认,服务器收到确认就会删除队列的消息
    @RabbitListener(queues = {"atguigu.queue.simple"})
    public void processMessage(String msq, Message message, Channel channel) {
        System.out.println("msq = " + msq);
//        byte[] body = message.getBody();
//        String s = new String(body);
//        System.out.println("s = " + s);
//        MessageProperties messageProperties = message.getMessageProperties();//消息属性:长度,字符编码,内容类型,优先级
//        System.out.println("messageProperties = " + messageProperties);

    }
    //----------------------------------------------------------------------------------------
    //默认采用自动处理确认消息,消费者获取消息处理后,自动给服务器发送异步确认,服务器收到确认就会删除队列的消息
    //工作对列
    @RabbitListener(queues = {"atguigu.queue.work"})
    public void processMessagework1(String msq, Message message, Channel channel) {
        System.out.println("work1 = " + msq);
    }

    @RabbitListener(queues = {"atguigu.queue.work"})
    public void processMessagework2(String msq, Message message, Channel channel) {
        System.out.println("work2 = " + msq);
    }
    //----------------------------------------------------------------------------------------
    @RabbitListener(queues = {"atguigu.exchange.fanout01"})
   public   void processMessagefanout01(String msq, Message message, Channel channel){
        System.out.println("fanout01 = "+ msq);
    }
    @RabbitListener(queues = {"atguigu.exchange.fanout02"})
    public   void processMessagefanout02(String msq, Message message, Channel channel){
        System.out.println("fanout02 = "+ msq);
    }
    //----------------------------------------------------------------------------------------
    @RabbitListener(queues = {"atguigu.queue.direct"})
    public   void processMessageRouting(String msq, Message message, Channel channel){
        System.out.println("Message Content = "+ msq);
    }
    //----------------------------------------------------------------------------------------
    //通配符
    @RabbitListener(queues = {"atguigu.queue.message"})
    public void processMessage01(String msq, Message message, Channel channel){
        System.out.println("message = " + msq);
    }
    @RabbitListener(queues = {"atguigu.queue.order"})
    public void processMessage02(String msq, Message message, Channel channel){
        System.out.println("order = " + msq);
    }

}